package Ms.controller;

import Result.Result;

import cn.dev33.satoken.annotation.SaCheckRole;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import Ms.service.ProjectService;
import Ms.service.UserService;

import java.util.HashMap;
import java.util.Map;

// StatsController.java
@RestController
@RequestMapping("/admin/stats")
public class StatsController {
    @Autowired
    private UserService userService;
    @Autowired
    private ProjectService projectService;

    @SaCheckRole("admin")
    @GetMapping("/summary")
    public Result getSummary() {
        Map<String, Integer> data = new HashMap<>();
        data.put("students", userService.countUsers("student"));
        data.put("teachers", userService.countUsers("teacher"));
        data.put("projects", Math.toIntExact(projectService.countProjects()));
        return Result.success(data);
    }
}


